<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加业务员</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
	</head>

	<style>
		.yanshi {
			height: 38px;
			line-height: 1.3;
			line-height: 38px\9;
			border: 1px solid #e6e6e6;
			background-color: #fff;
			border-radius: 2px;
			width: 211px;
		}
	</style>

	<body>
		<form class="mui-input-group gerenzl_group layui-form">
			<br />
			{if $Think.session.user_level==1 || $Think.session.user_level==4}
			<div class="layui-form-item" id='add_city' style='display: none;'>
				<label class="layui-form-label">代理商：</label>
				<div class="layui-input-block update_shurk" style="width: 230px;margin-top:5px">
					<select name="agency_id1" id='agency_id1' onchange="select_trade(this);" lay-ignore class="yanshi">
						<option value="0">选择代理商</option>
						{volist name="data" id="vo"}
						<option {if $res['agency_id1'] == $vo.id} selected {/if} value="{$vo.id}">{$vo.user_name}</option>
						{/volist}
					</select>
				</div>
			</div>
			<div class="layui-form-item" id='director' style='display: none;'>
				<label class="layui-form-label">运营商：</label>
				<div class="layui-input-block update_shurk">
					<select name="agency_id2" id='agency_id2' lay-ignore class="yanshi">
						<option value="0">选择运营商</option>
						{volist name="list" id="str"}
						<option {if $res['agency_id2'] == $str.id} selected {/if} value="{$str.id}">{$str.user_name}</option>
						{/volist}
					</select>
				</div>
			</div>
			{/if}
			{if $Think.session.user_level==2}
			<div class="layui-form-item" id='director' style='display: none;'>
				<label class="layui-form-label">运营商：</label>
				<div class="layui-input-block update_shurk">
					<select name="agency_id2" id='agency_id2' lay-ignore class="yanshi">
						<option value="0">选择运营商</option>
						{volist name="list" id="val"}
						<option {if $res['agency_id2'] == $val.id} selected {/if} value="{$val.id}">{$val.user_name}</option>
						{/volist}
					</select>
				</div>
			</div>
			{/if} 

			{if $Think.session.user_level==1 || $Think.session.user_level==3}
            <div class="layui-form-item" >
					<label class="layui-form-label">分佣比例</label>
					<div class="layui-input-block update_shurk">
						<input type="number" style="width: 40%;float: left;" name="sc_bili" lay-verify="required" id="sc_bili" value="{$res['sc_bili']}"  placeholder="分佣占充值比例" autocomplete="off" class="layui-input" ><span style="width: 10%;height:38px;line-height:38px;text-align:center;">%</span><p>(市场专员默认5%)</p>
					</div>
			</div> 
			{/if}
			<div class="layui-form-item update_btnbox">
				<div class="layui-input-block">
					<button class="layui-btn" type="button" lay-submit lay-filter="submit_from">立即提交</button>
				</div>
			</div>
			<input type="hidden" value="{$res['id']}" name="id">
		</form>
	</body>

</html>
<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>

<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
<script src="__PUBLIC__/static/layui/layui.all.js"></script>
<script>
	$(function() {
		var level = "{$Think.session.user_level}";
		if(level == 3) {
			$('#add_city').hide();
			$('#director').hide();
		} 

		if(level == 1 || level == 4) {
			$('#add_city').show();
			$('#director').show();
		} 
		if(level == 2) {
			$('#add_city').hide();
			$('#director').show();
		} 

	});
	//图片上传
	layui.use(['form'], function() {
		var $ = layui.jquery,
			form = layui.form;
		//监听表单提交
		form.on('submit(submit_from)', function(data) {
			tijiao();
			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
	});
	//提交表单
	function tijiao() {
		var user_level = "{$Think.session.user_level}";

		if(user_level == 1 || user_level == 4) {
			var agency_id1= $('#agency_id1').val();
			if(agency_id1 == '0') {
				layer.msg('请选择市代理商');
				return;
			}
		} 

		if(user_level == 1 || user_level == 4 || user_level == 2) {
			var agency_id2 = $('#agency_id2').val();
			if(agency_id2 == '0') {
				layer.msg('请选择运营商');
				return;
			}
		}

		if($('#sc_bili').val()<0){
				layer.msg('请输入正确的分佣比例', {time:1500});
				return false;
			}
		
		
		$.ajax({
			type: "post",
			url: "{:url('pt_edit')}",
			data: $('.layui-form').serialize(), //表单数据
			success: function(data) {
				var icon = 5;
				if(data.code == 200) {
					icon = 1;
					layer.msg(data.msg, {
						icon: icon,
						time: 1500 //2秒关闭（如果不配置，默认是3秒）
					}, function() {
						window.parent.location.reload();
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
						parent.layer.close(index);
					});
				} else {
					layer.msg(data.msg, {
						icon: icon,
						time: 1500 //2秒关闭（如果不配置，默认是3秒）
					});
				}
			},
			error: function(data) {
				var a = data;
			}
		});

	}

	function select_trade(obj) {
		var agency_id1 = $(obj).val();
		var lay = layer.load(0, {
			shade: false,
			time: 1.5 * 1000
		});
		$.ajax({
			type: 'post',
			url: "{:url('accounts/get_agency_id1')}",
			data: {
				agency_id1: agency_id1
			},
			success: function(data) {
				var list = data.data;
				if(list) {
					var html = "<option value='0'>选择运营商</option>";
					for(var i = 0; i < list.length; i++) {
						var trade = list[i];
						html += "<option value=" + trade['id'] + ">" + trade['user_name'] + "</option>";
					}
					$("#agency_id2").html(html);

				}
			}
		})

	}
</script>